package com.sql.azarias.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;

import com.sql.azarias.R;
import com.sql.azarias.adapter.MyFragmentPagerAdapter;
import com.sql.azarias.fragment.BelleFragment;
import com.sql.azarias.fragment.OneFragment;
import com.sql.azarias.ui.fragment.LiveFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ShangQiangLong on 2017/2/28.
 */

public class TabActivity extends BaseActivity{
    private TabLayout mTabLayout;
    private ViewPager mViewPager;
    private List<String> mTitleList = new ArrayList<>();//页卡标题集合
    private List<Fragment> mFragment = new ArrayList<Fragment>();//页卡视图集合
    private LayoutInflater mInflater;
    @Override
    protected void onCreate( Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tab);
        mTabLayout = (TabLayout)findViewById(R.id.tab);
        mViewPager= (ViewPager)findViewById(R.id.viewpager);
        mInflater=LayoutInflater.from(this);
        //添加页卡视图
        mFragment.add(new LiveFragment());
        mFragment.add(new BelleFragment());
        mFragment.add(new OneFragment());
        mFragment.add(new OneFragment());
        mFragment.add(new OneFragment());


        //添加页卡标题
        mTitleList.add("No:1");
        mTitleList.add("No:2");
        mTitleList.add("No:3");
        mTitleList.add("No:4");
        mTitleList.add("No:5");

        MyFragmentPagerAdapter adapter = new MyFragmentPagerAdapter(getSupportFragmentManager(), mTitleList, mFragment);
        mViewPager.setAdapter(adapter);
        //为TabLayout设置ViewPager
        mTabLayout.setupWithViewPager(mViewPager);
        //使用ViewPager的适配器
        mTabLayout.setTabsFromPagerAdapter(adapter);

    }

}
